package subject_set.lanqiao;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/10/25 16:37
 **/
public class Num4 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        int year = Integer.parseInt(s.substring(0, 4));
        int month = Integer.parseInt(s.substring(4, 6));
        int day = Integer.parseInt(s.substring(6, 8));
        LocalDate data = LocalDate.of(year, month, day);
        data = data.plusDays(1);
        String a = null;
        String b = null;
        boolean isFind = false;
        while(true){
            String dataToStr = data.toString().replace("-", "");
            if(isReverse(dataToStr.toCharArray())){
                if(!isFind){
                    isFind = true;
                    a = dataToStr;
                }
                if(isSuperRev(dataToStr.toCharArray())){
                    b = dataToStr;
                    break;
                }
            }
            data = data.plusDays(1);
        }
        System.out.println(a);
        System.out.println(b);
        scan.close();
    }
    private static boolean isReverse(char[] ch){
        int l = 0, r = ch.length-1;
        while(l < r){
            if(ch[l] != ch[r]) return false;
            l++; r--;
        }
        return true;
    }
    private static boolean isSuperRev(char[] ch){
        if(ch[0] == ch[2] && ch[0] == ch[5] && ch[0] == ch[7] &&
                ch[1] == ch[3] && ch[1] == ch[4] && ch[1] == ch[6])
            return true;
        return false;
    }
}